package com.renren.rrwx.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.renren.rrwx.R;
import com.renren.rrwx.model.Hero;
import com.renren.rrwx.model.PlayerHero;

/**
 * 用于显示我的属性的界面
 * 
 * @author Leon
 * 
 */
public class HeroPropView extends FrameLayout {

	// 姓名，称号，门派，排名
	TextView tvName, tvTitle, tvSchool, tvRank;
	// 当前状态
	TextView tvState;
	ProgressBar pbState;

	// 属性相关
	TextView tvHp, tvMp, tvAtk, tvDef, tvAgi;
	// 描述
	TextView tvDis;
	// 头像
	ImageView headImgView;

	public HeroPropView(Context context) {
		super(context);
		this.addView(View.inflate(context, R.layout.my_prop_view, null));
		//
		tvName = (TextView) findViewById(R.id.mp_tv_name);
		tvTitle = (TextView) findViewById(R.id.mp_tv_title);
		tvSchool = (TextView) findViewById(R.id.mp_tv_school);
		tvRank = (TextView) findViewById(R.id.mp_tv_rank);
		//
		tvState = (TextView) findViewById(R.id.mp_tv_state);
		pbState = (ProgressBar) findViewById(R.id.mp_state_progress);
		//
		tvHp = (TextView) findViewById(R.id.mp_tv_hp);
		tvMp = (TextView) findViewById(R.id.mp_tv_mp);
		tvAtk = (TextView) findViewById(R.id.mp_tv_atk);
		tvDef = (TextView) findViewById(R.id.mp_tv_def);
		tvAgi = (TextView) findViewById(R.id.mp_tv_agi);
		//
		tvDis = (TextView) findViewById(R.id.mp_tv_describe);

		headImgView = (ImageView) findViewById(R.id.mp_head_imageView);
	}

	/**
	 * 设置属性界面要显示的hero
	 * 
	 * @param hero
	 */
	private int type = 0;// 0普通好友，1玩家

	public void setHero(Hero hero) {

		if (hero instanceof PlayerHero) {
			type = 1;
		} else
			type = 0;
		// 开始初始化好友数据
		tvName.setText(hero.name);
		tvTitle.setText(hero.getTitle());
		tvSchool.setText(hero.getSchool());
		tvRank.setText(hero.getRank());
		//
		tvState.setText(hero.getStateNow());
		// pbState ;
		//
		tvHp.setText(hero.getProp(Hero.HP));
		tvMp.setText(hero.getProp(Hero.MP));
		tvAtk.setText(hero.getProp(Hero.ATK));
		tvDef.setText(hero.getProp(Hero.DEF));
		tvAgi.setText(hero.getProp(Hero.AGI));
		//
		tvDis.setText(hero.getDiscribe());

		// 头像
		Bitmap head = hero.getHeadImg();
		if (head != null)
			headImgView.setImageBitmap(head);
		else
			headImgView.setImageResource(R.drawable.default_head);
	}
}
